(function($, doc) {
	$.plusReady(function() {
		$.init();
		var user = app.getState();
		var uid = user.user_id;

		doc.getElementById('addcoin').addEventListener('tap', function() {
			$.openWindow({
				url: 'addcoin.html',
				id: 'addcoin'
			});
		});
		
		ethscan.getlist(function(data) {
			doc.getElementById('walletlist').innerHTML = template('wallet-template', {
				data: data,
				serverurl: serverurl
			});
			$(".friend-searchbox").on('input', '#searchInput', function() {
				var val = this.value;
				//console.log(val);
				if(val == '') {
					doc.querySelector(".mui-table-view-cell").style.display = '';
					
					doc.getElementById('walletlist').innerHTML = template('wallet-template', {
						data: data,
						serverurl: serverurl
					});
				} else {
					var newlist = {};
					var i = 0;
					for(var p in data) {
						var item = data[p];
						if(item['name'].indexOf(val) !== -1 || item['address'].indexOf(val) !== -1) {
							newlist[p] = item;
							i++;
						}
					}
					if(i > 0) {
						
						doc.getElementById('walletlist').innerHTML = template('wallet-template', {
							data: newlist,
							serverurl: serverurl
						});
						$('#walletlist').on('tap', 'input', function(){
							ethscan.setmyCoin(this, function(newlist) {
								var mainWin = plus.webview.getWebviewById('coin.html');
								mui.fire(mainWin, 'flashWallet', null);
							});
						});
					} else {
						$.toast("搜不到，试着点右上角添加");
					}
					
					//console.log('5');
				}
				//$('#walletlist').on('tap', 'input', setcoin);
			});
			ethscan.getmyCoin(function(data) {
				for(var p in data) {
					var item = data[p];
					if(item && item['address']) {
						var id = item['address'];
						//console.log(id);
						var eldom = document.getElementById(id);
						eldom && eldom.setAttribute('checked', true);
					}

				}
			});
			$('#walletlist').on('tap', 'input', function() {
				//console.log(JSON.stringify(this.id));
				//var el = this;
				ethscan.setmyCoin(this, function(data) {
					var mainWin = plus.webview.getWebviewById('coin.html');
					mui.fire(mainWin, 'flashWallet', null);
				});
		});
		});
	});

}(mui, document));